<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="对虾包装是否完好" prop="packingIntact">
        <el-input
          v-model="queryParams.packingIntact"
          placeholder="请输入对虾包装是否完好"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="急性肝胰腺坏死病" prop="ahpnsEms">
        <el-input
          v-model="queryParams.ahpnsEms"
          placeholder="请输入急性肝胰腺坏死病"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对虾白班浊病" prop="wsd">
        <el-input
          v-model="queryParams.wsd"
          placeholder="请输入对虾白班浊病"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="皮下及造血组织坏死病毒" prop="ihhnv">
        <el-input
          v-model="queryParams.ihhnv"
          placeholder="请输入皮下及造血组织坏死病毒"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="肛肠鲍冲" prop="ehp">
        <el-input
          v-model="queryParams.ehp"
          placeholder="请输入肛肠鲍冲"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="虾血虹彩病毒(SHIV)" prop="shiv">
        <el-input
          v-model="queryParams.shiv"
          placeholder="请输入虾血虹彩病毒(SHIV)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['simple:simpleReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['simple:simpleReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['simple:simpleReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['simple:simpleReport:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="simpleReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="样品报告ID" align="center" prop="orderDetailReportId" />
      <el-table-column label="对虾包装是否完好" align="center" prop="packingIntact" :formatter="packingIntactFormat" />
      <el-table-column label="急性肝胰腺坏死病" align="center" prop="ahpnsEms" :formatter="ahpnsEmsFormat" />
      <el-table-column label="对虾白班浊病" align="center" prop="wsd" :formatter="wsdFormat" />
      <el-table-column label="皮下及造血组织坏死病毒" align="center" prop="ihhnv" :formatter="ihhnvFormat" />
      <el-table-column label="肛肠鲍冲" align="center" prop="ehp" :formatter="ehpFormat" />
      <el-table-column label="虾血虹彩病毒(SHIV)" align="center" prop="shiv" :formatter="shivFormat" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['simple:simpleReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['simple:simpleReport:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改样品报告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="对虾包装是否完好" prop="packingIntact">
          <el-input v-model="form.packingIntact" placeholder="请输入对虾包装是否完好" />
        </el-form-item>
        <el-form-item label="急性肝胰腺坏死病" prop="ahpnsEms">
          <el-input v-model="form.ahpnsEms" placeholder="请输入急性肝胰腺坏死病" />
        </el-form-item>
        <el-form-item label="对虾白班浊病" prop="wsd">
          <el-input v-model="form.wsd" placeholder="请输入对虾白班浊病" />
        </el-form-item>
        <el-form-item label="皮下及造血组织坏死病毒" prop="ihhnv">
          <el-input v-model="form.ihhnv" placeholder="请输入皮下及造血组织坏死病毒" />
        </el-form-item>
        <el-form-item label="肛肠鲍冲" prop="ehp">
          <el-input v-model="form.ehp" placeholder="请输入肛肠鲍冲" />
        </el-form-item>
        <el-form-item label="虾血虹彩病毒(SHIV)" prop="shiv">
          <el-input v-model="form.shiv" placeholder="请输入虾血虹彩病毒(SHIV)" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSimpleReport, getSimpleReport, delSimpleReport, addSimpleReport, updateSimpleReport, exportSimpleReport } from "@/api/simple/simpleReport";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 样品报告表格数据
      simpleReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 对虾包装是否完好字典
      packingIntactOptions: [],
      // 急性肝胰腺坏死病字典
      ahpnsEmsOptions: [],
      // 对虾白班浊病字典
      wsdOptions: [],
      // 皮下及造血组织坏死病毒字典
      ihhnvOptions: [],
      // 肛肠鲍冲字典
      ehpOptions: [],
      // 虾血虹彩病毒(SHIV)字典
      shivOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        packingIntact: undefined,
        ahpnsEms: undefined,
        wsd: undefined,
        ihhnv: undefined,
        ehp: undefined,
        shiv: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_yes_no").then(response => {
      this.packingIntactOptions = response.data;
    });
    this.getDicts("spl_positive_negative").then(response => {
      this.ahpnsEmsOptions = response.data;
    });
    this.getDicts("spl_positive_negative").then(response => {
      this.wsdOptions = response.data;
    });
    this.getDicts("spl_positive_negative").then(response => {
      this.ihhnvOptions = response.data;
    });
    this.getDicts("spl_positive_negative").then(response => {
      this.ehpOptions = response.data;
    });
    this.getDicts("spl_positive_negative").then(response => {
      this.shivOptions = response.data;
    });
  },
  methods: {
    /** 查询样品报告列表 */
    getList() {
      this.loading = true;
      listSimpleReport(this.queryParams).then(response => {
        this.simpleReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 对虾包装是否完好字典翻译
    packingIntactFormat(row, column) {
      return this.selectDictLabel(this.packingIntactOptions, row.packingIntact);
    },
    // 急性肝胰腺坏死病字典翻译
    ahpnsEmsFormat(row, column) {
      return this.selectDictLabel(this.ahpnsEmsOptions, row.ahpnsEms);
    },
    // 对虾白班浊病字典翻译
    wsdFormat(row, column) {
      return this.selectDictLabel(this.wsdOptions, row.wsd);
    },
    // 皮下及造血组织坏死病毒字典翻译
    ihhnvFormat(row, column) {
      return this.selectDictLabel(this.ihhnvOptions, row.ihhnv);
    },
    // 肛肠鲍冲字典翻译
    ehpFormat(row, column) {
      return this.selectDictLabel(this.ehpOptions, row.ehp);
    },
    // 虾血虹彩病毒(SHIV)字典翻译
    shivFormat(row, column) {
      return this.selectDictLabel(this.shivOptions, row.shiv);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderDetailReportId: undefined,
        packingIntact: undefined,
        ahpnsEms: undefined,
        wsd: undefined,
        ihhnv: undefined,
        ehp: undefined,
        shiv: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderDetailReportId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加样品报告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderDetailReportId = row.orderDetailReportId || this.ids
      getSimpleReport(orderDetailReportId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改样品报告";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderDetailReportId != undefined) {
            updateSimpleReport(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addSimpleReport(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderDetailReportIds = row.orderDetailReportId || this.ids;
      this.$confirm('是否确认删除样品报告编号为"' + orderDetailReportIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSimpleReport(orderDetailReportIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有样品报告数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSimpleReport(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>